﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using FTP = FTPSClient;
using System.ComponentModel;
using System.IO;

namespace Vision.Core.ActivityComponents.IO.Ftp
{
	/// <summary>
	/// 
	/// </summary>
	[Designer(typeof(FtpUploadFileDesigner))]
    public class FtpUploadFile : NativeActivity
	{
		internal FTP.FTPSClient FtpClient { get; set; }

		/// <summary>
		/// Gets or sets the file name to save as on the FTP site.
		/// </summary>
		[Category("Input")]
		public InArgument<string> RemoteFileName { get; set; }

		/// <summary>
		/// Gets or sets the local path and name of the file to upload.
		/// </summary>
		[Category("Input")]
		public InArgument<string> LocalFileName { get; set; }

		/// <summary>
		/// 
		/// </summary>
		/// <param name="context"></param>
		protected override void Execute(NativeActivityContext context)
		{
			this.FtpClient = (FTP.FTPSClient)context.Properties.Find("5AED2CE1-FB3C-45B3-9CB7-3DC8CD5E4C56");

			if (this.FtpClient != null)
			{
				string remoteFileName = context.GetValue(this.RemoteFileName);
				string localFileName = context.GetValue(this.LocalFileName);

				this.FtpClient.PutFile(localFileName, remoteFileName);
			}
		}
	}
}
